package com.rd.student.jiaji.class4.suyan.zrrd.day29_0731;

import java.util.*;

public class exercise {
    private static int[] arr=new int[20];
    public static void main(String[] args) {
//test();
        test1();
//        test3();
//        test4();
    }

    public static void test() {
        HashSet<Integer> set = new HashSet<>();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要随机多少个数");
        int n = sc.nextInt();
        while (set.size() < n) {
            int number = (int) (Math.random() * 50);
            set.add(number);
        }
//        for (Integer obj : set) {
//            System.out.println(obj);
//        }
        System.out.println(set);

    }
    public static void  test1(){
        int[] arr=new int[20];
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要随机多少个数");
        int n=scanner.nextInt();
        int[] indexArr1=new int[arr.length];
        for (int i=0;i<indexArr1.length;i++){
            indexArr1[i]=-1;
        }
        System.out.println(Arrays.toString(indexArr1));
        for (int i=0;i<n;i++){
            int number=(int)(Math.random()*50);
            if (indexArr1[i]==-1){
                indexArr1[i]=number;
                System.out.println("随机出现"+number);
                System.out.println(arr[i]);
                System.out.println(Arrays.toString(indexArr1));
            }
            else {
                System.out.println("已经出现过了"+number);
                i--;
            }
        }
    }
    public static void test3(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要随机的个数");
        int n=scanner.nextInt();
        List<Integer> list=new ArrayList<>(n);
            for (int i=0;i<n;i++){
                int number=(int)(Math.random()*50);

                if (list.contains(number)){
                    System.out.println("随机已经出现"+number);
                    i--;
                    continue;
                }
                list.add(number);
                if (list.size()==n){
                    break;
                }
        }
        System.out.println(list);
        }
        public static void test4(){
        List<Integer>list=new ArrayList<>();
        for (int i=0;i<50;i++){
            list.add(i);
        }
        Collections.shuffle(list);
            Scanner scanner=new Scanner(System.in);
            System.out.println("请输入要随机的个数");
            int n=scanner.nextInt();
            for (int i=0;i<n;i++){
                System.out.println(list.get(i));
            }

        }
    }


